package Logic

import (
	"fmt"
	"math"
	"yz-go/Common"
	"yz-go/Models"
	"yz-go/Requests"
)

func GetJobListByModel(page int, size int, w map[string]interface{}) (rd Common.ResData) {
	var jobs []Models.RecruitJob
	var totalRows int64
	// 查询总行数
	errCount := Models.DB.Model(&Models.RecruitJob{}).Where(w).Count(&totalRows).Error
	if errCount != nil {
		fmt.Println(errCount)
		// 处理错误情况
		return Common.ResData{Code: Common.ERROR, Msg: errCount}
	}

	// 计算总页数
	totalPages := int(math.Ceil(float64(totalRows) / float64(size)))

	// 进行分页查询
	offset := (page - 1) * size
	errQuery := Models.DB.Debug().Where(w).Limit(size).Offset(offset).Find(&jobs).Error
	if errQuery != nil {
		fmt.Println(errQuery)
		// 处理错误情况
		return Common.ResData{Code: Common.ERROR, Msg: errQuery}
	}
	data := map[string]interface{}{"page": page, "size": size, "total": totalPages, "list": jobs}
	res := Common.ResData{Code: Common.SUCCESS, Msg: "", Data: data}
	return res
}

func CreateJobs(params Requests.NoteParams) (rd Common.ResData) {
	var jobs Requests.Params
	fmt.Print(jobs)
	fmt.Print(params)

	return rd
}
